library(tidyverse)
library(tidytext)
library(stringr)

dat = read.csv(file.choose()) %>% mutate(species='Arabica') # Arabica
dat1 = read.csv(file.choose()) %>% mutate(species='Robusta') # Robusta

dat2 = rbind(dat,dat1)

dat2$variable= reorder_within(dat2$variable,dat2$percent,dat2$species)

p1 = ggplot(dat2,aes(x=variable,percent))+geom_col(fill='purple1')+
  geom_text(aes(label = round(percent,1)),hjust=-0.3)+
  coord_flip()+labs(x='',y='Relative variable importance (%)')+
  theme_bw()+
  scale_y_continuous(limits=c(0,55),expand = c(0,0.01))+
  theme(axis.ticks.x = element_blank())+
  facet_wrap(~species,scales='free_y')+
  scale_x_reordered()

p1

setwd('C:/Users/Mr. Kasongi/Documents/SDM paper revisions and new results')

ggsave('variable_importance_combined.png',p1,height=6,width=9,units='in')

